<?php
/********************************************************************
Product    : Plotalot
Date       : 20 July 2011
Copyright  : Les Arbres Design 2011
Contact    : http://extensions.lesarbresdesign.info
Licence    : GNU General Public License
*********************************************************************/
defined('_JEXEC') or die('Restricted Access'); 

// check the PHP version

$php_version = phpversion();
if ($php_version{0} < 5)
	echo "<h2>Warning: You are running an old version of PHP ($php_version) This extension requires at least version 5.0. Some functions may not work properly</h2>";
	
// check the MySql version

$query = "SELECT version()";
$db	= &JFactory::getDBO();
$db->setQuery($query);
$mysql_version = $db->loadResult();
if ($mysql_version{0} < 5)
	echo "<h2>Warning: You are running an old version of MySql ($mysql_version) This extension requires at least version 5.0. Some functions may not work properly</h2>";

// check the Joomla version and get component version from the component manifest xml file

$version = new JVersion();
$joomla_version = $version->RELEASE;

switch ($joomla_version)
	{
	case '1.0':
		echo '<h3>'."Plotalot cannot run on this version of Joomla ($joomla_version)".'</h3>';
		return false;
	case '1.5':
		$component_version = $this->manifest->version[0]->_data;
		break;
	case '1.6';
	case '1.7';
		$component_version = $this->manifest->version;
		break;
	default:
		$component_version = $this->manifest->version;
		echo '<h3>'."This version of Plotalot has not been tested on this version of Joomla ($joomla_version). Some functions may not work properly.".'</h3>';
		break;
	}

// add new columns

add_column('#__plotalot', 'y_format', "SMALLINT NOT NULL DEFAULT '0' AFTER `y_end`");
add_column('#__plotalot', 'y_labels', "SMALLINT NOT NULL DEFAULT '-1' AFTER `y_format`");
add_column('#__plotalot', 'extra_parms', "text NOT NULL DEFAULT '' AFTER `y_labels`");

echo "<h3>Plotalot version $component_version</h3>";

//-------------------------------------------------------------------------------
// Check whether a table exists in the database. Returns TRUE if exists, FALSE if it doesn't
//
function table_exists($table)
{
	$db	=& JFactory::getDBO();
	$tables = $db->getTableList();
	$table = replaceDbPrefix($table);
	if (in_array($table,$tables))
		return true;
	else
		return false;
}

//-------------------------------------------------------------------------------
// Check whether a column exists in a table. Returns TRUE if exists, FALSE if it doesn't
//
function column_exists($table, $column)
{
	if (!table_exists($table))
		return false;
	$db	=& JFactory::getDBO();
	$fields = $db->getTableFields($table);
	if ($fields[$table] === null)
		return false;
	if (array_key_exists($column,$fields[$table]))
		return true;
	else
		return false;
}

//-------------------------------------------------------------------------------
// Add a column if it doesn't exist (the table must exist)
//
function add_column($table, $column, $details)
{
	if (column_exists($table, $column))
		return true;
	$query = 'ALTER TABLE `'.$table.'` ADD `'.$column.'` '.$details;
	$db	=& JFactory::getDBO();
	$db->setQuery($query);
	$db->query();
	if ($db->getErrorNum())
		{
		echo $db->stderr();
		return false;
		}
	return true;
}

//-------------------------------------------------------------------------------
// Joomla 1.7 took away replacePrefix() for some unknown reason
//
function replaceDbPrefix($sql)
{
	$app = &JFactory::getApplication();
	$dbprefix = $app->getCfg('dbprefix');
	return str_replace('#__',$dbprefix,$sql);
}

?>

Plotalot installed successfully


